﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class D03_Sniperscope : MonoBehaviour
{
    private Camera cam;//定义一个变量
    public float[] fovs;
    private int index = 0;
    private void Start()
    {
        cam = GetComponent<Camera>();//获取到组件
    }

    private void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            index++;
            //if (index == fovs.Length)//第一种写法
            //{
            //    index = 0;
            //}
            index = index % fovs.Length;//第二种写法
            cam.fieldOfView = fovs[index];
        }
    }
}